home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / java / jdirect mouse / source / pointstruct.java < prev   
Encoding:
Java Source  |  2000-06-23  |  2.9 KB  |  102 lines

  1. import  com.apple.mrj.jdirect.Struct;
  2. import  com.apple.mrj.jdirect.ByteArrayStruct;
  3.  
  4. /**
  5.  * Apple Worldwide Developer Technical Support
  6.  *
  7.  * A simple example of how to obtain the mouse location using the Mac OS Toolbox through JDirect 2.
  8.  *
  9.  * File: PointStruct.java
  10.  *
  11.  * <CODE>PointStruct</CODE> is a class which mimics the C struct <CODE>Point</CODE> defined in <CODE>MacTypes.h</CODE><BR><BR>
  12.  * This class contains a get and set method for each field in <CODE>Point</CODE>.<BR><BR>
  13.  * Using JDirect 2.0, a <CODE>PointStruct</CODE> can be passed to a native toolbox function
  14.  * that expects a pointer to a <CODE>Point</CODE> by using the <CODE>getByteArray()</CODE> method. 
  15.  *
  16.  * @author Apple Computer, Inc.
  17.  *
  18.  * Copyright ©1999 Apple Computer, Inc.
  19.  * All rights reserved.
  20.  *
  21.  * @version 1.0
  22.  * 4/15/1999 Shipped as 'JDirectMouse' sample.
  23.  *
  24.  * You may incorporate this sample code into your applications without
  25.  * restriction, though the sample code has been provided "AS IS" and the
  26.  * responsibility for its operation is 100% yours.  However, what you are
  27.  * not permitted to do is to redistribute the source as "Apple Sample
  28.  * Code" after having made changes. If you're going to re-distribute the
  29.  * source, we require that you make it clear in the source that the code
  30.  * was descended from Apple Sample Code, but that you've made changes.
  31.  */
  32. public class PointStruct extends ByteArrayStruct
  33. {
  34.     /**
  35.      * Constructs an uninitialized <CODE>PointStruct</CODE>
  36.      */
  37.     public PointStruct() {
  38.         super(sizeOfPoint);
  39.     }
  40.  
  41.     /**
  42.      * Constructs a <CODE>PointStruct</CODE> and initializes it with the data in another <CODE>Struct</CODE>. 
  43.      * Useful when a C struct <CODE>Point</CODE> is embedded in another C struct and you want to
  44.      * copy it out. 
  45.      * @param src the <CODE>Struct</CODE> containing the data to be copied
  46.      * @param offsetInSrc the offest in of the data in <CODE>src</CODE>
  47.      */
  48.     public PointStruct(Struct src, int offsetInSrc) {
  49.         super(sizeOfPoint);
  50.         byte[] bytes = src.getBytesAt(offsetInSrc, sizeOfPoint);
  51.         this.setBytesAt(0, bytes);
  52.     }
  53.  
  54.     /**
  55.      * Used only by subclasses of <CODE>PointStruct</CODE>
  56.      */
  57.     protected PointStruct(int size) {
  58.         super(size);
  59.     }
  60.  
  61.     /**
  62.      * in C: <CODE>short v</CODE>
  63.      * @return field <CODE>v</CODE> of <CODE>struct Point</CODE>
  64.      */
  65.     public final short getV() {
  66.         return getShortAt(0);
  67.     }
  68.  
  69.     /**
  70.      * in C: <CODE>short v</CODE>
  71.      * @param v sets field <CODE>v</CODE> of <CODE>struct Point</CODE>
  72.      */
  73.     public final void setV(short v) {
  74.         setShortAt(0, v);
  75.     }
  76.  
  77.     /**
  78.      * in C: <CODE>short h</CODE>
  79.      * @return field <CODE>h</CODE> of <CODE>struct Point</CODE>
  80.      */
  81.     public final short getH() {
  82.         return getShortAt(2);
  83.     }
  84.  
  85.     /**
  86.      * in C: <CODE>short h</CODE>
  87.      * @param h sets field <CODE>h</CODE> of <CODE>struct Point</CODE>
  88.      */
  89.     public final void setH(short h) {
  90.         setShortAt(2, h);
  91.     }
  92.  
  93.     /**
  94.      * Size of <CODE>struct Point</CODE> in bytes
  95.      */
  96.     public final static int sizeOfPoint = 4;
  97.  
  98.     public int getValue() {
  99.         return getIntAt(0);
  100.     }
  101. }
  102.